using System;

/// <summary>
/// 服务层基类
/// </summary>
public abstract class ServiceBase : IService
{
    public bool IsInitialized { get; protected set; }
    
    protected bool m_Disposed = false;
    
    public virtual void Initialize()
    {
        if (IsInitialized) return;
        
        OnInitialize();
        IsInitialized = true;
    }
    
    /// <summary>
    /// 子类实现具体的初始化逻辑
    /// </summary>
    protected abstract void OnInitialize();
    
    /// <summary>
    /// 子类实现具体的清理逻辑
    /// </summary>
    protected virtual void OnDispose() { }
    
    public virtual void Dispose()
    {
        if (m_Disposed) return;
        
        OnDispose();
        IsInitialized = false;
        m_Disposed = true;
    }
}
